package com.party.admin.biz.warn;

import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.party.core.model.system.SysConfig;
import com.party.core.service.notify.IInstanceService;
import com.party.core.service.system.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 短信警告服务接口
 * Created by wei.li
 *
 * @date 2017/8/4 0004
 * @time 10:09
 */

@Service
@Component(value = "smsWarnService")
public class SmsWarnService extends WarnTemplate {

    @Autowired
    private ISysConfigService sysConfigService;

    @Autowired
    private IInstanceService instanceService;

    private static final String SMS_WARN_RECEIVER = "smsWarnReceiver";

    /**
     * 获取预警阙值
     *
     * @return 预警阙值
     */
    @Override
    public Integer getNum() {
        return instanceService.count(0);
    }

    /**
     * 获取接受者
     *
     * @return 接受者列表
     */
    @Override
    public List<String> setReceiver() {
        SysConfig sysConfig = sysConfigService.findByCode(SMS_WARN_RECEIVER);
        if (null == sysConfig || Strings.isNullOrEmpty(sysConfig.getValue())){
            return Collections.EMPTY_LIST;
        }
        return Lists.newArrayList(Splitter.on(",").split(sysConfig.getValue()));
    }

    /**
     * 业务
     *
     * @return 业务逻辑
     */
    @Override
    public String getBusiness() {
        return "短信表";
    }
}
